/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.fzhucc.modules.technical.controller;

import com.fzhucc.annotation.Log;
import com.fzhucc.modules.technical.domain.TechnicalProjectLog;
import com.fzhucc.modules.technical.domain.dto.TechnicalProjectDistributionDto;
import com.fzhucc.modules.technical.service.TechnicalProjectLogService;
import com.fzhucc.modules.technical.domain.dto.TechnicalProjectLogQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
 * @author yyg
 * @date 2022-12-16
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "技术经理人：项目管理")
@RequestMapping("/api/technicalProjectLog")
public class TechnicalProjectLogController {

    private final TechnicalProjectLogService technicalProjectLogService;

    @GetMapping
    @Log("查询technicalProjectLog")
    @ApiOperation("查询technicalProjectLog")
    @PreAuthorize("@el.check('technicalProjectLog:list')")
    public ResponseEntity<Object> queryTechnicalProjectLog(TechnicalProjectLogQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(technicalProjectLogService.queryAll(criteria,pageable), HttpStatus.OK);
    }

    @Log("项目分配技术经理人")
    @ApiOperation("项目分配技术经理人")
    @PostMapping("/distribution")
    @PreAuthorize("@el.check('technicalProjectLog:list')")
    public ResponseEntity<Object> distribution(@RequestBody TechnicalProjectDistributionDto technicalProjectDistributionDto){
        technicalProjectLogService.dodistribution(technicalProjectDistributionDto);
        return new ResponseEntity<>(HttpStatus.OK);
    }


    @Log("技术经理人查询已分配自己的项目")
    @ApiOperation("技术经理人查询已分配自己的项目")
    @GetMapping("/getTechnicalProjectByLoginUser")
    @PreAuthorize("@el.check('technicalProjectLog:list')")
    public ResponseEntity<Object> getTechnicalProjectByLoginUser(Pageable pageable){
        return new ResponseEntity<>(technicalProjectLogService.getTechnicalProjectByLoginUser(pageable), HttpStatus.OK);
    }
}